package com.ssy.lingxi.platform.manage.controller.content;

import com.ssy.lingxi.common.controller.BaseController;
import com.ssy.lingxi.common.model.vo.PageVO;
import com.ssy.lingxi.common.response.PageData;
import com.ssy.lingxi.common.response.Wrapper;
import com.ssy.lingxi.platform.manage.entity.content.MemberNotice;
import com.ssy.lingxi.platform.manage.model.request.common.CommonIdRequest;
import com.ssy.lingxi.platform.manage.model.request.common.CommonStatusRequest;
import com.ssy.lingxi.platform.manage.model.request.content.ColumnTypeRequest;
import com.ssy.lingxi.platform.manage.model.request.content.MemberNoticePageRequest;
import com.ssy.lingxi.platform.manage.model.request.content.MemberNoticeRequest;
import com.ssy.lingxi.platform.manage.service.content.IMemberNoticeService;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.*;

import javax.annotation.Resource;
import javax.validation.Valid;
import java.util.List;

/**
 * @menu 内容能力-公告管理
 * @author wyx
 * @version 2.0.0
 * @date 2021-09-28
 */
@RestController
@RequestMapping("/manage/member/notice")
public class MemberNoticeController extends BaseController {

    @Resource
    private IMemberNoticeService memberNoticeService;

    /**
     * 根据栏目和会员信息获取所有公告
     * @param columnTypeRequest 请求参数
     * @return 操作结果
     */
    @GetMapping(value = "/findByColumnTypeMemberInfo")
    public Wrapper<List<MemberNotice>> findByColumnTypeMemberInfo(@Valid ColumnTypeRequest columnTypeRequest) {
        return memberNoticeService.findByColumnTypeMemberInfo(columnTypeRequest);
    }


    /**
     * 公告分页列表
     * @param request 请求参数
     * @return 查询结果
     */
    @GetMapping("/page")
    public Wrapper<PageData<MemberNotice>> page(@Valid MemberNoticePageRequest request) {
        return memberNoticeService.page(request, getSysUser());
    }

    /**
     * 公告详情
     * @param request 请求参数
     * @return 查询结果
     */
    @GetMapping(value = "/get")
    public Wrapper<MemberNotice> get(@Validated CommonIdRequest request) {
        return memberNoticeService.get(request);
    }

    /**
     * 新增公告
     * @param request 请求参数
     * @return 操作结果
     */
    @PostMapping(value = "/add")
    public Wrapper<Void> add(@RequestBody @Validated({MemberNoticeRequest.Add.class}) MemberNoticeRequest request) {
        return memberNoticeService.add(request, getSysUser());
    }

    /**
     * 修改公告
     * @param request 请求参数
     * @return 操作结果
     */
    @PostMapping(value = "/update")
    public Wrapper<Void> update(@RequestBody @Validated({MemberNoticeRequest.Update.class}) MemberNoticeRequest request) {
        return memberNoticeService.update(request, getSysUser());
    }

    /**
     * 上架/下架
     * @param request 请求参数
     * @return 操作结果
     */
    @PostMapping(value = "/updateStatus")
    public Wrapper<Void> updateStatus(@RequestBody @Validated({CommonStatusRequest.Shelf.class}) CommonStatusRequest request) {
        return memberNoticeService.updateStatus(request, getSysUser());
    }

    /**
     * 删除公告
     * @param request 请求参数
     * @return 操作结果
     */
    @PostMapping(value = "/delete")
    public Wrapper<Void> delete(@RequestBody @Validated CommonIdRequest request) {
        return memberNoticeService.delete(request, getSysUser());
    }

    /**
     * 根据栏目获取所有公告
     * @param columnType 栏目类型： 1-会员首页公告 2-注册须知 3-入库协议
     * @return 操作结果
     */
    @GetMapping(value = "/findAllByColumnType")
    public Wrapper<List<MemberNotice>> findAllByColumnType(Integer columnType) {
        return memberNoticeService.findAllByColumnType(columnType, getSysUser());
    }

    /**
     * 获取最新公告
     * @param pageVO 分页参数
     * @return 操作结果
     */
    @GetMapping(value = "/findNewestNotice")
    public Wrapper<PageData<MemberNotice>> findNewestNotice(@Valid PageVO pageVO) {
        return memberNoticeService.findNewestNotice(pageVO, getSysUser());
    }
}
